<template>
	<view class="mainpadding">
		<view class="xiahuaxian shangbj flexbetween " v-for="item in list.data" :key="item.id" @click="checkaddress(item)">
			<view class="">
				<view class="sanshier fonweight xiaohei">{{item.cityinfo}}{{item.address_detail}}</view>
				<view class="xiaohui margin_top2 strongtext">{{item.name}} {{item.mobile}}</view>
			</view>
			<u-icon name="edit-pen" color="#333333" size="28" @click="bianji(item.id)"></u-icon>
		</view>
		<view class="gudingdb ffffff mainpadding" @click="tzxzdz">
			<view class="bigbtn">新增地址</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type:"",
				list: {
					data: []
				},
			}
		},
		onLoad(options) {
			if(options.type){
				this.type = options.type
			}
		},
		onShow() {
			this.init();
		},
		methods: {
			init() {
				let _this = this;
				httpRequest.request("/api/user/addressList", 'GET', {
				}, false, false, true).then(res => {
					this.list.data = res.data
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			bianji(id) { //编辑跳转
				uni.navigateTo({
					url: '/pages_mypage/xinzengdz?id=' + id
				})
			},
			// 跳转新增地址
			tzxzdz() {
				uni.navigateTo({
					url: '/pages_mypage/xinzengdz'
				})
			},
			checkaddress(item){
				if(this.type==1){
					uni.$emit("addressId",item.id)
					uni.navigateBack(1)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.shangbj {
		margin-top: 30rpx;
	}

	.shangbj:first-child {
		margin-top: 0rpx;
	}
</style>